package cn.spring.ly.service;

import javax.jms.JMSException;
import javax.jms.TextMessage;

import org.apache.activemq.command.ActiveMQTextMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;

import cn.spring.ly.entity.SysUser;

/**
 * 发送消息业务类
 * 
 * @author acer
 *
 */
@Service
public class MessageService {

	@Autowired
	JmsMessagingTemplate jmsTemplate;
	
	public void sendGoodsMessage(String msg) throws JMSException {
		jmsTemplate.convertAndSend("good_msg", msg);
		System.out.println("发送消息成功");
//		TextMessage textMsg = new  ActiveMQTextMessage();
//		textMsg.setText(msg);
//		textMsg.setJMSExpiration(1000l);
//		jmsTemplate.send("good_msg", (Message)textMsg );
	}

	public void sendOrderMessage(String msg) {

	}

	public void sendUserMessage() {

		//注册用户
		SysUser user = new SysUser();
		user.setUserId(1002l);
		user.setUsername("张三");
		user.setEmail("913365252@qq.com");
		//
		
		jmsTemplate.convertAndSend("user_msg", JSON.toJSONString(user));
		System.out.println("发送消息成功");
	}
}
